package chapter1.socket.task.task1;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/*
1:服务器上存有多个用户对象,考虑用List或者Map（对象包括用户和密码），
客户端通过socket登录(输入用户名和密码)，如果成功，输出欢迎信息，失败给出提示。
 */
public class Client {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Socket socket = null;
        PrintWriter out = null;
        try {
            socket = new Socket("127.00.1", 1700);
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            out = new PrintWriter(socket.getOutputStream(), true);
            String s = in.readLine();
            System.out.println(s);
            out.println(input.next());//输入用户名

            String s1 = in.readLine();
            System.out.println(s1);
            out.println(input.next());//输入密码

            String s2 = in.readLine();
            System.out.println(s2);


        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (socket != null) {
                    socket.close();
                    out.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
